package com.glsc.ngateway.common.base.repo.mysql.gateway.other;

import com.glsc.ngateway.common.base.domain.mysql.gateway.other.TradeAccountShareHolder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TradeAccountShareHolderRepository extends JpaRepository<TradeAccountShareHolder, Integer>, JpaSpecificationExecutor<TradeAccountShareHolder> {

    @Query(value = "select m from TradeAccountShareHolder m where m.dataStatus=0 " +
//            "and (:#{#paramSearchDto.shareHolderAccount} is null OR m.shareHolderAccount = :#{#paramSearchDto.shareHolderAccount})  " +
//            "and (:#{#paramSearchDto.shareHolderAccountName} is null OR m.shareHolderAccountName = :#{#paramSearchDto.shareHolderAccountName})  " +
            "and (:#{#paramSearchDto.shareHolderAccount} is null OR m.shareHolderAccount LIKE CONCAT('%',:#{#paramSearchDto.shareHolderAccount},'%') )  " +
            "and (:#{#paramSearchDto.shareHolderAccountName} is null OR m.shareHolderAccountName LIKE CONCAT('%',:#{#paramSearchDto.shareHolderAccountName},'%') )  " +
            "and (:#{#paramSearchDto.market} is null OR m.market = :#{#paramSearchDto.market})  " +
            "and (:#{#paramSearchDto.status} is null OR m.status = :#{#paramSearchDto.status})  " +
            "and (:#{#paramSearchDto.shareHolderUseDepartmentId} is null OR m.shareHolderUseDepartmentId = :#{#paramSearchDto.shareHolderUseDepartmentId})  " +
            "and (:#{#paramSearchDto.fundIndex} is null OR m.fundIndex LIKE CONCAT('%',:#{#paramSearchDto.fundIndex},'%')) " +
            "and (:#{#paramSearchDto.fundName} is null OR m.fundName LIKE CONCAT('%',:#{#paramSearchDto.fundName},'%')) " +
            "and (:#{#paramSearchDto.tradUnit} is null OR m.tradUnit = :#{#paramSearchDto.tradUnit}) " +
            "and (:#{#paramSearchDto.openDate} is null OR m.openDate LIKE CONCAT('%',:#{#paramSearchDto.openDate},'%')) " +
            "and (:#{#paramSearchDto.remark1} is null OR m.remark1 LIKE CONCAT('%',:#{#paramSearchDto.remark1},'%')) " +
            "and (:#{#paramSearchDto.statusSelectName} is null OR m.statusSelectName LIKE CONCAT('%',:#{#paramSearchDto.statusSelectName},'%')) " +
            "and (:#{#paramSearchDto.marketSelectName} is null OR m.marketSelectName LIKE CONCAT('%',:#{#paramSearchDto.marketSelectName},'%')) " +
//            "and (:#{#paramSearchDto.belongDeptId} is null OR m.belongDeptId = :#{#paramSearchDto.belongDeptId})  " +
//            "and (:#{#paramSearchDto.opSupportName} is null OR m.opSupportName LIKE CONCAT('%',:#{#paramSearchDto.opSupportName},'%') )  " +
//            "and (:#{#paramSearchDto.systemSummary} is null OR m.systemSummary LIKE CONCAT('%',:#{#paramSearchDto.systemSummary},'%') )  " +
//            "and (:#{#paramSearchDto.processDefineKey} is null OR m.processDefineKey = :#{#paramSearchDto.processDefineKey} )  " +
//            "and (:#{#paramSearchDto.systemCode} is null OR m.systemCode = :#{#paramSearchDto.systemCode} )  " +
//            "and (:#{#paramSearchDto.beginDateLocalDate} is null OR m.processCreateTime >= :#{#paramSearchDto.beginDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.endDateLocalDate} is null OR m.processCreateTime <= :#{#paramSearchDto.endDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.hasProcessEnd} is null OR m.isClose = :#{#paramSearchDto.hasProcessEnd} )  " +
//            "and (coalesce(:#{#paramSearchDto.adminList}, null) is null or m.systemAdminAccount in (:#{#paramSearchDto.adminList})) " +
            "")
    Page<TradeAccountShareHolder> searchByParam(Pageable pageable, TradeAccountShareHolder paramSearchDto);

    @Modifying
    @Query("update TradeAccountShareHolder sc set sc.dataStatus = 1 where sc.shareHolderAccount in :accounts")
    void updateDataStatusByShareHolderAccounts(@Param(value = "accounts") List<String> collect);
}



